
<template>
    <view>
        <public-module></public-module>
        <wlk-navbar title="修改密码" navbarType='0'></wlk-navbar>
        <view class="pwd-content br08">
            <u-form :rules="rules" :labelStyle="{fontSize:'40rpx'}" :model="form" ref="uForm" labelPosition="top" labelWidth="100" :borderBottom="false">
                <u-form-item
                        prop="newpassword"
                >
                    <u--input
                            clearable
                            v-model="form.newpassword"
                            border="none"
                            placeholder="请输入新密码"
                    ></u--input>
                </u-form-item>
            </u-form>
        </view>
        <view class="wlk-fixed-btn">
            <u-button :customStyle="{
                    fontWeight: 'bold',
			        borderRadius:'8px',
			          width:'92%'
                }" :disabled="!form.newpassword" :color="themeColor" size="large" @click="submit" text="保存"></u-button>
        </view>
    </view>
</template>

<script>
    var _self;
    import { mapActions, mapGetters } from 'vuex';
    import { toUrl } from '@/wlkutils/tools';
    export default {
        computed: {
            ...mapGetters(['themeColor'])
        },
        data() {
            return {
                form: {
                    newpassword:''
                },
                rules: {
                    'newpassword': {
                        type: 'string',
                        required: true,
                        message: '请填写新密码',
                        trigger: ['blur', 'change']
                    }
                },
            }
        },
        onLoad(e){
            _self = this;
        },
        onReady() {
            this.$refs.uForm.setRules(this.rules)
        },
        methods: {
            ...mapActions(["getUserInfo"]),
            submit() {
                this.$refs.uForm.validate().then(res => {
                    uni.$u.http.post('user/changePwd', _self.form).then(res => {
                        _self.getUserInfo(res.data.token);
                        uni.$u.toast(res.msg);
                        setTimeout(function () {
                            toUrl('/pages/index/user');
                        },1000)
                    })
                })
            },
        }
    }
</script>
<style lang="scss" >
    .pwd-content{
        width: 92%;
        padding: 30rpx 30rpx;
        background-color: #FFFFFF;
        margin: 40% auto 0 auto;
        box-shadow: 0 2px 4px rgba(0,0,0,.02);
    }
    .wlk-fixed-btn{
        box-shadow: 0px -5px 5px rgba(0, 0, 0, 0);
        background-color: transparent;
    }
</style>

